<?php
require_once "config.php";

//接收 get 参数
$n = $_GET["name"];
$p = $_GET["password"];

//var_dump($n);
//var_dump($p);

//去 user 数据库里找 有没有匹配的值
$sql = "SELECT * FROM `user` WHERE `name` LIKE '$n' AND `password` LIKE '$p'";
//执行sql
$result = $conn->query($sql);

if($result->num_rows > 0){
    //echo “可以登录”
    //找到这个用的id是多少
    $res = $result->fetch_assoc();
    $id = $res["id"];
    var_dump($id);
    //把id存到Session
    $_SESSION['id'] = $id;

    //跳转到首页
    header("Location:index.php");
}else{
    echo "登录失败（用户名或密码错误）";
}
